package cn.powertime.evaluation.app.controller;

import cn.powertime.evaluation.entity.DbqNews;
import cn.powertime.evaluation.facade.PersonalCenterFacade;
import cn.powertime.evaluation.vo.*;
import cn.powertime.evaluation.web.controller.BaseController;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.ImmutableMap;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * <p>
 * 个人中心 前端控制器
 * </p>
 *
 * @author Yang Xin
 * @since 2019-09-29
 */
@RestController
@RequestMapping("/app/personalCenter")
@Api(value = "/app/personalCenter", tags = "个人中心接口", produces = MediaType.ALL_VALUE)
@Validated
public class AppPersonalCenterController extends BaseController {

    @Autowired
    private PersonalCenterFacade personalCenterFacade;

    @ApiOperation(value = "个人中心-关注数/发帖数")
    @PostMapping(value = "/count")
    public Object count() {
        RespFocusCount count = this.personalCenterFacade.count();
        return success(count);
    }

    @ApiOperation(value = "个人中心-个人主页-帖子接口")
    @PostMapping(value = "/postings")
    public Object postings(@Validated @RequestBody PageVo vo) {
        Page<RespPersonalPostingsListVo> list = this.personalCenterFacade.personalPostingsList(vo);
        return success(list);
    }

    @ApiOperation(value = "个人中心-个人主页-关注接口")
    @PostMapping(value = "/focusUserList")
    public Object focusUserList(@Validated @RequestBody PageVo vo) {
        Page<RespFocusListVo> list = this.personalCenterFacade.focusUserList(vo);
        return success(list);
    }

    @ApiOperation(value = "个人中心-个人主页-收藏接口")
    @PostMapping(value = "/collects")
    public Object collects(@Validated @RequestBody PageVo vo) {
        Page<RespPersonalPostingsListVo> list = this.personalCenterFacade.collects(vo);
        return success(list);
    }

    @ApiOperation(value = "个人中心-个人主页-消息接口")
    @PostMapping(value = "/messages")
    public Object messages(@Validated @RequestBody PageVo vo) {
        IPage<DbqNews> list = this.personalCenterFacade.messages(vo);
        return success(list);
    }

    @ApiOperation(value = "个人中心-学习记录接口",response = WebRespCourseRecordListVo.class)
    @PostMapping(value = "/learningRecords")
    public Object learningRecords(@Validated @RequestBody PageVo vo) {
        IPage<WebRespCourseRecordListVo> list = personalCenterFacade.learningRecords(vo);
        return success(list);
    }

    @ApiOperation(value = "个人中心-我的题库-已答试卷接口")
    @PostMapping(value = "/answerRecord")
    public Object answerRecord(@Validated @RequestBody ParamPageVo<ReqAnswerTestPaperSearchVo> vo) {
        Page<RespAnswerTestPaperVo> list = this.personalCenterFacade.answerRecord(vo);
        return success(list);
    }

    @ApiOperation(value = "个人中心-我的题库-查看试卷接口")
    @GetMapping(value = "/testPaperView")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "testPaperId", value = "试卷id", required = true),
            @ApiImplicitParam(name = "resultId", value = "考试结果id(试卷类型为6时传0)", required = true),
            @ApiImplicitParam(name = "type", value = "试卷类型，1:课后作业，2：课程刷题，3真题模拟，4：测评练习，5：自查工具，6：智能练习", required = true, example = "1")})
    public Object testPaperView(@NotNull(message = "试卷id不能为空") @RequestParam Long testPaperId, @NotNull(message = "考试结果id不能为空") @RequestParam Long resultId, @NotNull(message = "试卷id不能为空") @RequestParam Integer type) {
        RespTopicGroupVo vo = this.personalCenterFacade.testPaperView(testPaperId, resultId, type);
        if(vo == null) {
            return success(ImmutableMap.of());
        }
        return success(vo);
    }

    @ApiOperation(value = "个人中心-我的题库-收藏习题接口")
    @PostMapping(value = "/collectTopicList")
    public Object collectTopicList(@Validated @RequestBody PageVo vo) {
        Page<RespAnswerTopicListVo> list = this.personalCenterFacade.collectTopicList(vo);
        return success(list);
    }

    @ApiOperation(value = "个人中心-我的题库-用户错题接口")
    @PostMapping(value = "/wrongTopicList")
    public Object wrongTopicList(@Validated @RequestBody PageVo vo) {
        Page<RespAnswerTopicListVo> list = this.personalCenterFacade.wrongTopicList(vo);
        return success(list);
    }

    /*@ApiOperation(value = "个人中心-个人资料接口")
    @PostMapping("/updateUser")
    public Object updateUser(@Validated @RequestBody ReqUserUpdateVo vo) {
        boolean b = this.personalCenterFacade.updateUser(vo);
        if (b) {
            return success("修改成功");
        }
        return error("修改失败");
    }*/

}
